var $m=$('.m');//
var $head=$('#head');//头
var $Contentp=$('.content>p');//文字内容
var $wz=$('article.individual');//完整文章块
var $sq=$wz.find('.yc');//收起
var fTop=null;//点击阅读全文时候需要的

//头部
$head.children().last().children().first().on('tap',fnA);
//幕罩隐藏，和弹窗
$m.on('tap',fnNone)//幕罩
.children().on('tap',function(e){e.stopPropagation();})//幕罩内容防止冒泡
.children('button').first().on('tap',fnA)//立即打开App
.parent().children('span').on('tap',fnNone)//span
//出了评论外的文字操作栏 && 除了了更多。幕罩显示
$('article.individual>.idea>div:first-child>div:not(:nth-child(3))').on('tap',fnBlock)//点赞
$('.gd>:not(:first-child)').on('tap',fnBlock);

$wz.on('tap',function(){
	var $content=$(this).find('div.content');//内容
	//有阅读全文则发动
	if($content.is('.l2')&&$content.children('span.lan').length){
		var $sq=$(this).find('.yc');//收起
		var $f=$sq.parent();//功能框
		//修改样式
		$content.removeClass('l2').find('span.lan').addClass('yc');
		$content.prev('div').removeClass('hidden');//图片
		$sq.removeClass('yc');
		//固定位置
		sName='scroll.scroll'+Math.random();
		var thisObj=$(this)[0].getBoundingClientRect();
		if(thisObj.bottom-$(window).height()-$f.height()-parseInt($f.css('margin-top'))>0&&thisObj.top-$(window).height()<-6*parseInt($(document.documentElement).css('font-size'))){
			$f.addClass('f');
		}
		$(window).on(sName,()=>fnBottom($(this),$f,$sq,sName));
	}
})
$sq.on('tap',function(event){
	$(this).addClass('yc')//收起
	.parent().removeClass('f')//功能框
	.parent().find('div.content').addClass('l2')//内容
	.find('span.lan').removeClass('yc')//阅读全文
	.parent().prev('div').addClass('hidden');//对于有图片的div
	event.stopPropagation();
})
function fnBottom(obj,fTop,sq,sName){//功能框的出现方式
	var jx=obj[0].getBoundingClientRect();
	var objB=jx.bottom;
	var objT=jx.top;
	var maxObjB=objB-$(window).height()-fTop.height()-parseInt(fTop.css('margin-top'));
	if(sq.is('.yc')){
		$(window).off(sName);
		return;
	}
	var bB=!fTop.is('.f')&&!sq.is('.yc');
	if(objB-$(window).height()<=0){//底部
		fTop.removeClass('f');
	}else if(!fTop.is('.f')&&(maxObjB>0&&objT-$(window).height()<-6*parseInt($(document.documentElement).css('font-size')))){
		fTop.addClass('f');
	}else if(fTop.is('.f')&&objT-$(window).height()>=-6*parseInt($(document.documentElement).css('font-size'))){
		fTop.removeClass('f');
	}
}
function fnA(e){
	alert('该功能暂没开通');
	e.stopPropagation();
}
function fnNone(e){
	$m.css('display','none');
	$(window).off('resize.mz');
	e.stopPropagation();
}
function fnBlock(e){
	$m.css('display','block');
	e.stopPropagation();
}
var mH=()=>$m.height($(window).height());

(()=>{
	$('#foot').on('tap',fnA);
	$('#hidden').height($head.height());//头部替身高度初始化
	$(window).scroll(()=>{//监测scroll的头部
		if($head.offset().top!==0){
			$head.addClass('headbox');
		}else{
			$head.removeClass('headbox')
		}
	});
	mH();
})();
//设置
// $Contentp.filter('.hidden').height(parseInt($Contentp.filter('.hidden').eq(0).css('font-size'))*2+9);
